#pragma once
#ifndef __HSM_LUA_TYPES_H__
#define __HSM_LUA_TYPES_H__

//---------------------------------------------------------------------------
/**
 * per state context data used by hula
 */
typedef struct hula_context_rec hula_context_t;
struct hula_context_rec
{
    /**
     * core context data: hula_context_rec extends the base context.
     */
    hsm_context_t core;

    /**
     * lua state that's managed by this state
     * ( this is generally constant across the whole machine )
     */
    lua_State *L;

    /**
     * a luaL_ref to lua data generated by the state's entry
     * currently uses the registry, would it be better (faster?) to use state tables?
     */
    int lua_ref;

    /**
     * count the number of times this hula_context_rec is shared amongst parents and children
     * dont release the lua data until the last state using the lua_ref data is done.
     */
    int lua_ref_count;    
};

//---------------------------------------------------------------------------
/**
 * user data structure used for lua based statemachines
 */
typedef struct hula_machine_rec hula_machine_t;
struct hula_machine_rec
{
    hsm_context_machine_t hsm;
    hula_context_t ctx;
    int topstate;  // useful for debugging, and to_string
};

#endif //__HSM_LUA_TYPES_H__
